package com.bt.lms.ui.action.school_education.archives.basicMes;

import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

/**
 * 学籍基本信息的编辑事件
 */
public class ScrollRecordEditAction implements EventHandler {

    private VBox totalVBox;

    private Integer baseWidth = 1230;

    private VBox vBox;

    public ScrollRecordEditAction(VBox totalVBox, VBox vBox) {
        this.totalVBox = totalVBox;
        this.vBox = vBox;
    }


    @Override
    public void handle(Event event) {
        HBox btnBox = new HBox();
        btnBox.setPrefWidth(1230);
        btnBox.setAlignment(Pos.CENTER_RIGHT);
        btnBox.setSpacing(10);
        Insets insets1 = new Insets(10,50,10,10);
        btnBox.setPadding(insets1);
        Button saveBtn = new Button("保存");
        Button cancelBtn = new Button("取消");
        btnBox.getChildren().add(saveBtn);
        btnBox.getChildren().add(cancelBtn);
        BtnStyle.saveBtn(saveBtn);
        BtnStyle.cancelBtn(cancelBtn);

        ObservableList<Node> children = this.totalVBox.getChildren();
        children.set(2,btnBox);


        //验证事件
        EditScrollVerify editScrollVerify = new EditScrollVerify(this.totalVBox);
        saveBtn.setOnAction(editScrollVerify);
        saveBtn.setCursor(Cursor.HAND);
        cancelBtn.setCursor(Cursor.HAND);


        //学籍基本信息信息的主盒子
        VBox totalHBox = new VBox();
        totalHBox.setPrefWidth(baseWidth);
        totalHBox.setSpacing(10);

        HBox enterSchoolDayBox = new HBox();
        enterSchoolDayBox.setSpacing(10);
        Label stuNoLab = new Label("学员编号");
        stuNoLab.setPrefWidth(baseWidth/8);
        TextField stuNoTF = new TextField();
        stuNoTF.setId("stuNoTF");
        stuNoTF.setPrefWidth(baseWidth/4);
        enterSchoolDayBox.getChildren().addAll(stuNoLab,stuNoTF);
        totalHBox.getChildren().add(enterSchoolDayBox);

        HBox two = new HBox();
        two.setSpacing(10);
        Label nameLab = new Label("姓名");
        nameLab.setPrefWidth(baseWidth/8);
        TextField nameTF = new TextField();
        nameTF.setId("nameTF");
        nameTF.setPrefWidth(baseWidth/4);
        Label iDTypeLab = new Label("证件类型");
        iDTypeLab.setPrefWidth(baseWidth/8);
        ComboBox iDTypeTF = new ComboBox<>();
        iDTypeTF.getItems().addAll("身份证","士官证","学生证","驾驶证","护照","港澳通行证");
        iDTypeTF.getSelectionModel().select(0);
        iDTypeTF.setId("iDTypeTF");
        iDTypeTF.setPrefWidth(baseWidth/4);
        two.getChildren().addAll(nameLab,nameTF,iDTypeLab,iDTypeTF);
        totalHBox.getChildren().add(two);

        HBox three = new HBox();
        three.setSpacing(10);
        Label enterSchoolTimeLab = new Label("入学年月");
        enterSchoolTimeLab.setPrefWidth(baseWidth/8);
        DatePicker enterSchoolTimeTF = new DatePicker();
        enterSchoolTimeTF.setId("enterSchoolTimeTF");
        enterSchoolTimeTF.setPrefWidth(baseWidth/4);
        Label iDCardLab = new Label("证件号码");
        iDCardLab.setPrefWidth(baseWidth/8);
        TextField iDCardDP = new TextField();
        iDCardDP.setId("iDCardDP");
        iDCardDP.setPrefWidth(baseWidth/4);
        three.getChildren().addAll(enterSchoolTimeLab,enterSchoolTimeTF,iDCardLab,iDCardDP);
        totalHBox.getChildren().add(three);


        HBox four = new HBox();
        four.setSpacing(10);
        Label classNameLab = new Label("班级名称");
        classNameLab.setPrefWidth(baseWidth/8);
        TextField classNameTF = new TextField();
        classNameTF.setId("classNameTF");
        classNameTF.setPrefWidth(baseWidth/4);
        Label lengthOfSchoolingLab = new Label("学制");
        lengthOfSchoolingLab.setPrefWidth(baseWidth/8);
        TextField lengthOfSchoolingTF = new TextField();
        lengthOfSchoolingTF.setId("lengthOfSchoolingTF");
        lengthOfSchoolingTF.setPrefWidth(baseWidth/4);
        four.getChildren().addAll(classNameLab,classNameTF,lengthOfSchoolingLab,lengthOfSchoolingTF);
        totalHBox.getChildren().add(four);

        HBox five = new HBox();
        five.setSpacing(10);
        Label studyCenterLab = new Label("学习中心");
        studyCenterLab.setPrefWidth(baseWidth/8);
        TextField studyCenterTF = new TextField();
        studyCenterTF.setId("studyCenterTF");
        studyCenterTF.setPrefWidth(baseWidth/4);
        Label enrollPlanLab = new Label("招生计划");
        enrollPlanLab.setPrefWidth(baseWidth/8);
        TextField enrollPlanTF = new TextField();
        enrollPlanTF.setId("enrollPlanTF");
        enrollPlanTF.setPrefWidth(baseWidth/4);
        five.getChildren().addAll(studyCenterLab,studyCenterTF,enrollPlanLab,enrollPlanTF);
        totalHBox.getChildren().add(five);


        HBox six = new HBox();
        six.setSpacing(10);
        Label specialtyLab = new Label("专业");
        specialtyLab.setPrefWidth(baseWidth/8);
        TextField specialtyTF = new TextField();
        specialtyTF.setId("specialtyTF");
        specialtyTF.setPrefWidth(baseWidth/4);
        Label currentStateLab = new Label("学生当前状态");
        currentStateLab.setPrefWidth(baseWidth/8);
        ComboBox currentStateCB = new ComboBox<>();
        currentStateCB.setId("currentStateCB");
        currentStateCB.setPrefWidth(baseWidth/4);
        currentStateCB.getItems().addAll("在读","休学","退学");
        six.getChildren().addAll(specialtyLab,specialtyTF,currentStateLab,currentStateCB);
        totalHBox.getChildren().add(six);

        children.set(3,totalHBox);


        /**
         * 取消按钮的匿名内部类
         */
        cancelBtn.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                HBox hBox = new HBox();
                hBox.setPrefWidth(baseWidth);
                Insets insets1 = new Insets(0,50,0,10);
                hBox.setPadding(insets1);
                hBox.setAlignment(Pos.CENTER_RIGHT);
                Button editBtn = new Button("💻编辑");
                hBox.getChildren().add(editBtn);
                //按钮样式
                BtnStyle.saveBtn(editBtn);
                editBtn.setCursor(Cursor.HAND);

                //给编辑按钮加事件
                ScrollRecordEditAction scrollRecordEditAction = new ScrollRecordEditAction(totalVBox,vBox);
                editBtn.setOnAction(scrollRecordEditAction);

                children.set(2,hBox);
                children.set(3,vBox);

            }
        });
    }
}
